/* $Id: ProblemStatementEntry.java 137 2011-08-29 20:33:36Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.datatypes;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import alt.djudge.frontend.shared.dto.admin.AdminDTOEntry;
import alt.djudge.frontend.shared.dto.admin.ProblemStatementEntryDTO;


@PersistenceCapable(detachable="true")
public class ProblemStatementEntry extends AbstractEntry
{
	private static final long serialVersionUID = 1L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	
	@Override
	public Long getId()
	{
		return id;
	}
	
	@Override
	public void setId(Long id)
	{
		this.id = id;
	}
	
	@Persistent
	private Long localeId = null;
	
	@Persistent
	private Long problemId = null;
	
	@Persistent
	private byte[] statement = null;

	public void setLocaleId(Long localeId)
	{
		this.localeId = localeId;
	}

	public Long getLocaleId()
	{
		return localeId;
	}

	public void setProblemId(Long problemId)
	{
		this.problemId = problemId;
	}

	public Long getProblemId()
	{
		return problemId;
	}

	public void setStatement(String statement)
	{
		this.statement = statement.getBytes();
	}

	public String getStatement()
	{
		return new String(statement);
	}
	
	@Override
	public void fromDTO(AdminDTOEntry dtoEntry)
	{
		setLocaleId(Long.parseLong(dtoEntry.getFieldValue(1)));
		setProblemId(Long.parseLong(dtoEntry.getFieldValue(2)));
		setStatement(dtoEntry.getFieldValue(3));
	}

	@Override
	public AdminDTOEntry ownAdminDTO()
	{
		String[] data = new String[] {
			getId().toString(),
			getLocaleId().toString(),
			getProblemId().toString(),
			getStatement()
		};
		return new ProblemStatementEntryDTO(data);
	}	
}
